package liu.thread.jiehai;

/**
 * 线程问题
 * @author My
 *
 */
public class Accont {
	private int money=1000;
	private int cs=0;
	private int jie=0;
	private int hai=0;

	
	

	public synchronized boolean getMoney() {
		try {
			
			/*if(money==0){
				notify();
				wait();
				return true;
			}*/
			
		if(cs==2){
			cs=0;
			notify();
			wait();
		}
		cs++;
		jie++;
		System.out.println("借了100元");
		money=money-100;
		System.out.println(Thread.currentThread().getName()+"现在共有"+money);
		
		if(jie==20){
			notify();
			return false;
		}
		
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return true;
	}

	public synchronized boolean setMoney() {
		
		try {
		notify();
		hai++;
		System.out.println("还了200元");
		money=money+200;
		System.out.println(Thread.currentThread().getName()+"现在共有"+money);
		
		if(hai==10){
			notify();
			return false;
		}
			wait();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return true;
	}

}
